package com.logistics.account.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.account.entity.model.AccountSave;
import com.logistics.utils.security.EncryptionUtils;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author zhiyu.fan
 * @since 2024-05-10
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_account")
public class Account implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String account;

    private String password;

    private String erpUserId;

    private String erpDeptCode;

    private String erpUniqueId;

    private String code;

    private String userName;

    private String mobile;

    private String email;

    private String wx;

    private String qq;

    private String province;

    private String city;

    private String area;

    private String address;

    private String post;

    private String organization;

    private String dep;

    private String createOrgCode;

    private String createDepCode;

    private String creator;

    private Date createTime;

    private String updater;

    private Date updateTime;

    public Account(){

    }

    public Account(AccountSave save){
        this.id = StringUtils.isNotNull(save.getId()) ? Integer.parseInt(save.getId()) : null;
        this.account = save.getAccount();
        this.erpUserId = save.getAccount();
        this.password = StringUtils.isNotNull(save.getPassword()) ? EncryptionUtils.md5Encode(save.getPassword()) : null;
        this.code = save.getCode();
        this.userName = save.getUserName();
        this.mobile = save.getMobile();
        this.email = save.getEmail();
        this.wx = save.getWx();
        this.qq = save.getQq();
        this.province = save.getProvince();
        this.city = save.getCity();
        this.area = save.getArea();
        this.address = save.getAddress();
        this.post = save.getPost();
        this.organization = save.getOrganization();
        this.dep = save.getDep();
        this.erpUniqueId = save.getErpUniqueId();
        this.erpDeptCode = save.getErpDeptCode();
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.creator = save.getCreator();
        this.createTime = DateUtils.stringToDateFormat(save.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
        this.updater = save.getUpdater();
        this.updateTime = DateUtils.stringToDateFormat(save.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS);
    }

    public static Account build(AccountSave save){
        return new Account(save);
    }


    public static Account build(String password){
        Account account = new Account();
        account.setPassword(password);
        return account;
    }

}
